#pragma once

#include <Windows.h>
#include <WindowsX.h>
#include <tchar.h>

#include <GdiPlus.h>
using namespace Gdiplus;


class Win32Application
{
public:
	Win32Application();
	virtual ~Win32Application();

	// application functions
	LRESULT Create(int width, int height, const TCHAR* title);
	void Release();
	void Close();
	int Run();
	void Update();

	// windows message handlers
	virtual HRESULT OnCreate();
	virtual void OnRelease();
	virtual bool OnMessage(UINT, WPARAM, LPARAM);
	virtual void OnKeyDown(DWORD key);
	virtual void OnChar(char c);
	virtual void OnPaint(Graphics& graphics);
	virtual void OnMouseDown(DWORD button, int x, int y);
	virtual void OnMouseUp(DWORD button, int x, int y);
	virtual void OnMouseMove(DWORD button, int x, int y);

	inline HWND Handle() const { return m_hwnd; }

protected:
	BOOL CreateWin32Application(int width, int height, const TCHAR* title);

private:
	static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

	ULONG_PTR	m_gdip;
	HWND		m_hwnd;

	HDC			m_screenDC;

	HDC			m_memoryDC;
	HBITMAP		m_memoryBmp;
};

